package com.vincent.kdp.js;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.util.Log;
import android.webkit.JavascriptInterface;
import com.vincent.baseapp.util.SPUtil;
import com.vincent.kdp.Activity.AddConsumeActivity;
import com.vincent.kdp.Activity.GoodsDetailActivity;
import com.vincent.kdp.Activity.RepairGoodsActivity;
import com.vincent.kdp.Activity.WareHouseGoodsActivity;
import com.vincent.kdp.util.BaseParam;

public class GoodsDetailOperator {

    private Activity activity;
    private String barCode;
    Handler mHandler = new Handler();
    public GoodsDetailOperator(Activity activity,String barCode) {
        this.activity = activity;
        this.barCode=barCode;
    }

    @JavascriptInterface
    public String getDeviceId(){
        return BaseParam.getDeviceId();
    }

    @JavascriptInterface
    public String getBarCode(){
        Log.i("code", "传值--：" + barCode);
        return BaseParam.getCurrentBarCode();
    }

    @JavascriptInterface
    public void refresh(String barcode){
        activity.finish();
        Intent intent = new Intent(activity, GoodsDetailActivity.class);
        Log.i("code", "刷新--：" + barCode);
        intent.putExtra("barCode", BaseParam.getCurrentBarCode());
        activity.startActivity(intent);
    }

    /**
     * 添加消费
     * @param barCode
     * @param name
     * @param price
     */
    @JavascriptInterface
    public void addConsume( final String barCode,final String name,final String price){

        activity.runOnUiThread(new Runnable() {
            public void run() {
                Intent intent =new Intent(activity, AddConsumeActivity.class);
                intent.putExtra("type","goodsDetail");
                intent.putExtra("barCode", barCode);
                intent.putExtra("name", name);
                intent.putExtra("price", price);
                Log.d("AddConsumeActivity",name+"----"+barCode+"----"+price);
                activity.startActivity(intent);
            }
        });
    }

    /**
     * 跳转到展示店的数据
     */
    @JavascriptInterface
    public void jumpWareHouseList(final String title, final String departId, final String cStyleNum){
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Intent intent=new Intent(activity,WareHouseGoodsActivity.class);
                intent.putExtra("title",title);
                intent.putExtra("departId",departId);
                intent.putExtra("cStyleNum",cStyleNum);
                activity.startActivity(intent);
            }
        });
    }

    @JavascriptInterface
    public String getEmpId(){
        return SPUtil.getString("empId");
    }


}  